<?php

/**
 * This is the model class for table "prefix_page".
 *
 * The followings are the available columns in table 'prefix_page':
 * @property string $page_id
 * @property string $page_pid
 * @property string $page_url
 * @property string $page_url_full
 * @property string $page_title
 * @property string $page_text
 * @property string $page_date_add
 * @property string $page_date_edit
 * @property string $page_seo_keywords
 * @property string $page_seo_description
 * @property integer $page_active
 * @property integer $page_main
 * @property integer $page_sort
 * @property Page $parentPage
 * @property array(Page) $pages
 */
class Page extends LsActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Page the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return Config::Get('db.table.page');
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('page_url, page_url_full, page_title, page_text, page_date_add, page_sort', 'required'),
			array('page_active, page_main, page_sort', 'numerical', 'integerOnly'=>true),
			array('page_pid', 'length', 'max'=>11),
			array('page_url', 'length', 'max'=>50),
			array('page_url_full', 'length', 'max'=>254),
			array('page_title', 'length', 'max'=>200),
			array('page_seo_keywords, page_seo_description', 'length', 'max'=>250),
			array('page_date_edit', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('page_id, page_pid, page_url, page_url_full, page_title, page_text, page_date_add, page_date_edit, page_seo_keywords, page_seo_description, page_active, page_main, page_sort', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'parentPage' => array(self::BELONGS_TO, 'Page', 'page_pid'),
			'pages' => array(self::HAS_MANY, 'Page', 'page_pid'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'page_id' => 'Page',
			'page_pid' => 'Page Pid',
			'page_url' => 'Page Url',
			'page_url_full' => 'Page Url Full',
			'page_title' => 'Page Title',
			'page_text' => 'Page Text',
			'page_date_add' => 'Page Date Add',
			'page_date_edit' => 'Page Date Edit',
			'page_seo_keywords' => 'Page Seo Keywords',
			'page_seo_description' => 'Page Seo Description',
			'page_active' => 'Page Active',
			'page_main' => 'Page Main',
			'page_sort' => 'Page Sort',
		);
	}
}